"use strict";
cc._RF.push(module, '112c6MMhp5NzIk74/dfawwI', 'MainRoot');
// scripts/Game/MainRoot.ts

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
Object.defineProperty(exports, "__esModule", { value: true });
var gameEngine_1 = require("../engines/gameEngine");
var data_control_1 = require("../engines/libs/data_control");
var Enum_1 = require("./Enum");
var ConfigService_1 = require("./Services/ConfigService");
var LevelSystem_1 = require("./System/LevelSystem");
var UISystem_1 = require("./System/UISystem");
var MainRoot = /** @class */ (function () {
    function MainRoot() {
        this.uiRoot = null;
        this.systemes = null;
        this.services = null;
        this.configTable = null;
        this.configNewestTable = null;
        this.levelSystem = null;
        this.uiSystem = null;
        this.gameBundleName = 'gameBundle';
        this.frameBundleName = 'GameFrameBundle';
        this.gotTips = false;
        this.gotAnswer = false;
        this.gameEnd = false;
        this.curLoadBundleName = null;
        this.platName = null;
    }
    Object.defineProperty(MainRoot.prototype, "GotTips", {
        get: function () {
            return this.gotTips;
        },
        set: function (value) {
            // console.warn("改动了提示获取", value);
            this.gotTips = value;
        },
        enumerable: false,
        configurable: true
    });
    ;
    Object.defineProperty(MainRoot.prototype, "GotAnswer", {
        get: function () {
            return this.gotAnswer;
        },
        set: function (value) {
            // console.warn("改动了答案获取", value);
            this.gotAnswer = value;
        },
        enumerable: false,
        configurable: true
    });
    ;
    Object.defineProperty(MainRoot.prototype, "UIRoot", {
        get: function () {
            return this.uiRoot;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MainRoot.prototype, "Data_Cont", {
        get: function () {
            return data_control_1.default;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MainRoot.prototype, "UIModel", {
        get: function () {
            return gameEngine_1.default.getModules().uiControlModule;
        },
        enumerable: false,
        configurable: true
    });
    MainRoot.prototype.GetBundle = function (bundle) {
        // console.info("GetBundle", bundle)
        this.curLoadBundleName = bundle;
        return cc.assetManager.getBundle(bundle);
    };
    Object.defineProperty(MainRoot.prototype, "frameBundle", {
        get: function () {
            return cc.assetManager.getBundle(this.frameBundleName);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MainRoot.prototype, "gameBundle", {
        get: function () {
            return cc.assetManager.getBundle(this.gameBundleName);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MainRoot.prototype, "ConfigSerive", {
        get: function () { return this.configTable; },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MainRoot.prototype, "LevelSystem", {
        get: function () { return this.levelSystem; },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MainRoot.prototype, "UISystem", {
        get: function () { return this.uiSystem; },
        enumerable: false,
        configurable: true
    });
    MainRoot.prototype.GameInit = function () {
        return __awaiter(this, void 0, void 0, function () {
            var before, tt;
            var _this = this;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        before = Date.now();
                        // console.log("---<<<<<<游戏逻辑框架初始化>>>>>>---");
                        return [4 /*yield*/, new Promise(function (resolve, reject) {
                                cc.assetManager.loadBundle(_this.frameBundleName, function (err) {
                                    if (err) {
                                        console.error("逻辑框架分包加载错误", err);
                                        reject();
                                        return;
                                    }
                                    // console.log("---<<<<<<游戏逻辑框架分包加载完毕>>>>>>---");
                                    resolve();
                                });
                            })];
                    case 1:
                        // console.log("---<<<<<<游戏逻辑框架初始化>>>>>>---");
                        _a.sent();
                        cc.assetManager.loadBundle("normalMode", function (err) {
                            if (err) {
                                // console.error("normal游戏包加载错误");
                                return;
                            }
                        });
                        return [4 /*yield*/, this.ServiceInit()];
                    case 2:
                        _a.sent();
                        this.SystemInit();
                        tt = window['tt'];
                        if (tt) {
                            tt.getSystemInfo({
                                complete: (function (res) {
                                    if (res) {
                                        _this.platName = res.appName;
                                        // console.warn("app名称", this.platName);
                                    }
                                })
                            });
                        }
                        // console.log("--->>>>>>>>>>游戏逻辑框架初始化完毕,耗时:", Date.now() - before, "ms");
                        return [2 /*return*/, Promise.resolve()];
                }
            });
        });
    };
    /**是否能开启添加桌面  */
    MainRoot.prototype.isShortcutOpen = function () {
        if (this.platName == "Toutiao"
            || this.platName == "XiGua"
            || this.platName == "news_article_lite") {
            return false;
        }
        return true;
    };
    MainRoot.prototype.ServiceInit = function () {
        return __awaiter(this, void 0, void 0, function () {
            var array, index, element;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        this.configTable = new ConfigService_1.default();
                        this.services = [this.configTable];
                        array = this.services;
                        index = 0;
                        _a.label = 1;
                    case 1:
                        if (!(index < array.length)) return [3 /*break*/, 4];
                        element = array[index];
                        return [4 /*yield*/, element.ServiceInit()];
                    case 2:
                        _a.sent();
                        _a.label = 3;
                    case 3:
                        index++;
                        return [3 /*break*/, 1];
                    case 4: return [2 /*return*/];
                }
            });
        });
    };
    MainRoot.prototype.SystemInit = function () {
        this.levelSystem = new LevelSystem_1.default();
        this.uiSystem = new UISystem_1.default();
        this.systemes = [this.levelSystem, this.uiSystem];
        var array = this.systemes;
        for (var index = 0; index < array.length; index++) {
            var element = array[index];
            element.SystemInit();
        }
    };
    MainRoot.prototype.SetUIRoot = function (node) {
        this.uiRoot = node;
    };
    MainRoot.prototype.GameEnd = function (win) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                if (this.gameEnd) {
                    return [2 /*return*/];
                }
                this.gameEnd = true;
                gameEngine_1.default.emit(Enum_1.GAME_EVENT.ON_GAME_END, win);
                this.uiSystem.ClosePage(Enum_1.PAGE.INGAMEPAGE);
                return [2 /*return*/];
            });
        });
    };
    return MainRoot;
}());
function Gen() {
    try {
        window["mainRoot"] = new MainRoot();
        return window["mainRoot"];
    }
    catch (e) {
        console.error(e, "主模式引擎创建失败");
    }
}
var mainRoot = Gen();
exports.default = mainRoot;

cc._RF.pop();